package com.nisum.mocksimulator.notifier;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import net.contentobjects.jnotify.JNotifyListener;

@Component
public class DirectoryListener implements JNotifyListener {
	@Value("false")
	private boolean isFileRenamed;
	@Value("false")
	private boolean isFileModified;
	@Value("false")
	private boolean isFileDeleted;
	@Value("false")
	private boolean isFileCreated;
	@Value("0")
	private int wd;
	@Value("")
	private String rootPath;
	@Value(".")
	private String oldFileName;
	@Value("")
	private String fileName;
	
	public int getWd() {
		return wd;
	}
	public String getRootPath() {
		return rootPath;
	}
	public String getOldFileName() {
		return oldFileName;
	}
	public String getFileName() {
		return fileName;
	}
	public boolean isFileRenamed() {
		return isFileRenamed;
	}
	public void setFileRenamed(boolean isFileRenamed) {
		this.isFileRenamed = isFileRenamed;
	}
	public boolean isFileModified() {
		return isFileModified;
	}
	public void setFileModified(boolean isFileModified) {
		this.isFileModified = isFileModified;
	}
	public boolean isFileDeleted() {
		return isFileDeleted;
	}
	public void setFileDeleted(boolean isFileDeleted) {
		this.isFileDeleted = isFileDeleted;
	}
	public boolean isFileCreated() {
		return isFileCreated;
	}
	public void setFileCreated(boolean isFileCreated) {
		this.isFileCreated = isFileCreated;
	}
	
    public void fileRenamed(int wd, String rootPath, String oldName, String newName) {
      print("renamed " + rootPath + " : " + oldName + " -> " + newName);
    }
    
    public void fileModified(int wd, String rootPath, String name) {
    	print("modified " + rootPath + " : " + name);
        this.isFileModified = true;
        this.wd = wd;
        this.rootPath = rootPath;
        this.fileName = name;
    }
    
    public void fileDeleted(int wd, String rootPath, String name) {
      print("deleted " + rootPath + " : " + name);
    }
    
    public void fileCreated(int wd, String rootPath, String name) {
      print("created " + rootPath + " : " + name);
      this.isFileCreated = true;
      this.wd = wd;
      this.rootPath = rootPath;
      this.fileName = name;
    }
    
    void print(String msg) {
      System.err.println(msg);
    }
}
